<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 29] 29.14 java.text.NumberFormat (JDK 1.1)</TITLE>
<META NAME="author" CONTENT="David Flanagan">
<META NAME="date" CONTENT="Thu Jul 31 16:33:15 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java in a Nutshell">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java in a Nutshell" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch29_13.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 29<br>The java.text Package</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch29_15.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JNUT2-CH-29-SECT-14">29.14 java.text.NumberFormat (JDK 1.1)</A></h2>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-29-SECT-14.1"></A></h3>
</DIV>

<P CLASS=para>
This class formats and parses numbers in a locale-specific
way.  As an abstract class, it cannot be instantiated
directly, but it provides a number of static methods that
return instances of a concrete subclass which you can use
for formatting.  The <tt CLASS=literal>getInstance()</tt> method returns a
<tt CLASS=literal>NumberFormat</tt> object suitable for normal formatting of
numbers in either the default locale or in a specified
locale.  <tt CLASS=literal>getCurrencyInstance()</tt> and
<tt CLASS=literal>getPercentInstance()</tt> return <tt CLASS=literal>NumberFormat</tt> objects for
formatting numbers that represent monetary amounts and
percentages in either the default locale or in a specified
locale.  <tt CLASS=literal>getAvailableLocales()</tt> returns an array of
locales for which <tt CLASS=literal>NumberFormat</tt> objects are available.

<P CLASS=para>
Once you have created a suitable <tt CLASS=literal>NumberFormat</tt> object, you
may customize its locale-independent behavior with
<tt CLASS=literal>setMaximumFractionDigits()</tt>, <tt CLASS=literal>setGroupingUsed()</tt>
and similar <tt CLASS=literal>set</tt> methods.  In order to
customize the locale-dependent behavior, you can use
<tt CLASS=literal>instanceof</tt> to test if the <tt CLASS=literal>NumberFormat</tt>
object is an instance of <tt CLASS=literal>DecimalFormat</tt>, and if so,
cast it to that type.  The <tt CLASS=literal>DecimalFormat</tt> class
provides complete control over number formatting.  Note,
however, that a <tt CLASS=literal>NumberFormat</tt> customized in this way
may no longer be appropriate for the desired locale.

<P CLASS=para>
After creating and customizing a <tt CLASS=literal>NumberFormat</tt>
object, you can use the various <tt CLASS=literal>format()</tt> methods to
convert numbers to strings or string buffers, and you can
use the <tt CLASS=literal>parse()</tt> or <tt CLASS=literal>parseObject()</tt> methods to
convert strings to numbers.

<P CLASS=para>
The constants defined by this class are intended to be used by the <tt CLASS=literal>FieldPosition</tt> object.

<P CLASS=para>
The <tt CLASS=literal>NumberFormat</tt> class in not intended for the
display of very large or very small numbers that require
exponential notation, and it may not gracefully handle
infinite or <tt CLASS=literal>NaN</tt> (not-a-number) values.

<DIV CLASS=screen>
<P>
<PRE>
public abstract class <tt CLASS=literal>NumberFormat</tt> extends Format implements Cloneable {
    // <tt CLASS=literal>Default Constructor: public NumberFormat()</tt>
    // <tt CLASS=literal>Constants</tt>
            public static final int <tt CLASS=literal>FRACTION_FIELD</tt>;
            public static final int <tt CLASS=literal>INTEGER_FIELD</tt>;
    // <tt CLASS=literal>Class Methods</tt>
            public static Locale[] <tt CLASS=literal>getAvailableLocales</tt>();
            public static final NumberFormat <tt CLASS=literal>getCurrencyInstance</tt>();
            public static NumberFormat <tt CLASS=literal>getCurrencyInstance</tt>(Locale <tt CLASS=literal>inLocale</tt>);
            public static final NumberFormat <tt CLASS=literal>getInstance</tt>();
            public static NumberFormat <tt CLASS=literal>getInstance</tt>(Locale <tt CLASS=literal>inLocale</tt>);
            public static final NumberFormat <tt CLASS=literal>getNumberInstance</tt>();
            public static NumberFormat <tt CLASS=literal>getNumberInstance</tt>(Locale <tt CLASS=literal>inLocale</tt>);
            public static final NumberFormat <tt CLASS=literal>getPercentInstance</tt>();
            public static NumberFormat <tt CLASS=literal>getPercentInstance</tt>(Locale <tt CLASS=literal>inLocale</tt>);
    // <tt CLASS=literal>Public Instance Methods</tt>
            public Object <tt CLASS=literal>clone</tt>();  //<tt CLASS=literal> Overrides Format</tt>
            public boolean <tt CLASS=literal>equals</tt>(Object <tt CLASS=literal>obj</tt>);  //<tt CLASS=literal> Overrides Object</tt>
            public final StringBuffer <tt CLASS=literal>format</tt>(Object <tt CLASS=literal>number</tt>, StringBuffer <tt CLASS=literal>toAppendTo</tt>, FieldPosition <tt CLASS=literal>pos</tt>);  //<tt CLASS=literal> Defines Format</tt>
            public final String <tt CLASS=literal>format</tt>(double <tt CLASS=literal>number</tt>);
            public final String <tt CLASS=literal>format</tt>(long <tt CLASS=literal>number</tt>);
            public abstract StringBuffer <tt CLASS=literal>format</tt>(double <tt CLASS=literal>number</tt>, StringBuffer <tt CLASS=literal>toAppendTo</tt>, FieldPosition <tt CLASS=literal>pos</tt>);
            public abstract StringBuffer <tt CLASS=literal>format</tt>(long <tt CLASS=literal>number</tt>, StringBuffer <tt CLASS=literal>toAppendTo</tt>, FieldPosition <tt CLASS=literal>pos</tt>);
            public int <tt CLASS=literal>getMaximumFractionDigits</tt>();
            public int <tt CLASS=literal>getMaximumIntegerDigits</tt>();
            public int <tt CLASS=literal>getMinimumFractionDigits</tt>();
            public int <tt CLASS=literal>getMinimumIntegerDigits</tt>();
            public int <tt CLASS=literal>hashCode</tt>();  //<tt CLASS=literal> Overrides Object</tt>
            public boolean <tt CLASS=literal>isGroupingUsed</tt>();
            public boolean <tt CLASS=literal>isParseIntegerOnly</tt>();
            public abstract Number <tt CLASS=literal>parse</tt>(String <tt CLASS=literal>text</tt>, ParsePosition <tt CLASS=literal>parsePosition</tt>);
            public Number <tt CLASS=literal>parse</tt>(String <tt CLASS=literal>text</tt>) throws ParseException;
            public final Object <tt CLASS=literal>parseObject</tt>(String <tt CLASS=literal>source</tt>, ParsePosition <tt CLASS=literal>parsePosition</tt>);  //<tt CLASS=literal> Defines Format</tt>
            public void <tt CLASS=literal>setGroupingUsed</tt>(boolean <tt CLASS=literal>newValue</tt>);
            public void <tt CLASS=literal>setMaximumFractionDigits</tt>(int <tt CLASS=literal>newValue</tt>);
            public void <tt CLASS=literal>setMaximumIntegerDigits</tt>(int <tt CLASS=literal>newValue</tt>);
            public void <tt CLASS=literal>setMinimumFractionDigits</tt>(int <tt CLASS=literal>newValue</tt>);
            public void <tt CLASS=literal>setMinimumIntegerDigits</tt>(int <tt CLASS=literal>newValue</tt>);
            public void <tt CLASS=literal>setParseIntegerOnly</tt>(boolean <tt CLASS=literal>value</tt>);
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-29-SECT-14.2">Hierarchy:</A></h3>

<P CLASS=para>
Object->Format(Serializable, Cloneable)->NumberFormat(Cloneable)

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-29-SECT-14.3">Extended By:</A></h3>

<P CLASS=para>
ChoiceFormat, 
DecimalFormat

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-29-SECT-14.4">Passed To:</A></h3>

<P CLASS=para>
DateFormat.setNumberFormat()

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-29-SECT-14.5">Returned By:</A></h3>

<P CLASS=para>
DateFormat.getNumberFormat(), 
NumberFormat.getCurrencyInstance(), 
NumberFormat.getInstance(), 
NumberFormat.getNumberInstance(), 
NumberFormat.getPercentInstance()

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-29-SECT-14.6">Type Of:</A></h3>

<P CLASS=para>
DateFormat.numberFormat

</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch29_13.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch29_15.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>java.text.MessageFormat (JDK 1.1)</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>java.text.ParseException (JDK 1.1)</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
